﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using KingRoad.EPM.SafetyManagementBLL.Domain;
using KingRoad.EPM.SafetyManagementEntity.Model;
using Unis.Framework.Core.Utility;
using KingRoad.EPM.SafetyManagementDAL.ScmCostPlanMainService;
using ScmCostPlanService;


namespace KingRoad.EPM.SafetyManagementBLL.UIRules
{
    /// <summary> 
    /// 客户端业务处理类。 
    /// 文件生成时间 2017/2/6 13:53:28
    /// </summary> 
    public class ScmCostplanmainUIRule
    {
        private readonly IScmCostplanmainService _scmCostplanmainService;
        private  IScmCostplanService _scmCostplanService;

        public ScmCostplanmainUIRule() { }

        /// <summary> 
        /// construct function... 
        /// </summary> 
        public ScmCostplanmainUIRule(IScmCostplanmainService scmCostplanmainService)
        {
            _scmCostplanmainService = scmCostplanmainService;
            _scmCostplanService = new ScmCostplanService();
        }

        
        /// <summary>
        /// 获取费用计划信息
        /// </summary>
        /// <returns></returns>
        public List<ScmCostplanmainInfo> GetAllCostplanmain()
        {
            var list = _scmCostplanmainService.GetEntityList();
            return list;
        }
        /// <summary>
        /// 根据条件查询费用计划信息
        /// </summary>
        /// <param name="numCurrentPage">当前页</param>
        /// <param name="numPerPage">每页数据大小</param>
        /// <param name="orderByField">排序字段名称</param>
        /// <param name="totalRecord">总数据量</param>
        /// <param name="sqlCondition">sql查询条件</param>
        /// <returns></returns>
        public List<ScmCostplanmainInfo> GetAllCostplanmainForPage(int numCurrentPage, int numPerPage,
                                                                        string orderByField, out int totalRecord, string sqlCondition)
        {
            var list = _scmCostplanmainService.GetEntityListByContionRe(numCurrentPage, numPerPage, orderByField, out totalRecord, sqlCondition);
            return list;
        }
        /// <summary>
        /// 根据id获取费用计划信息
        /// </summary>
        /// <returns></returns>
        public ScmCostplanmainInfo GetCostplanmainById(Guid id)
        {
            var spminfo = _scmCostplanmainService.GetEntityById(id);
            return spminfo;
        }
        /// <summary>
        /// 添加费用计划信息
        /// </summary>
        /// <returns></returns>
        public int AddCostplanmain(ScmCostplanmainInfo AddEntity)
        {
            return _scmCostplanmainService.InsertEntity(AddEntity);
        }
        /// <summary>
        /// 修改费用计划信息
        /// </summary>
        /// <returns></returns>
        public int UpdateCostPlanmain(ScmCostplanmainInfo UpdateEntity)
        {
            return _scmCostplanmainService.UpdateEntity(UpdateEntity);
        }
        /// <summary>
        /// 删除费用计划信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int DeleteCostplanmain(string id)
        {
            var cp = _scmCostplanService.DeleteEntityByStringFID(id);
            return _scmCostplanmainService.DeleteEntityByStringID(id);
        }

        /// <summary>
        /// 根据Fid获取费用计划子表信息
        /// </summary>
        /// <returns></returns>
        public List<ScmCostplanInfo> GetCostplanByFId(Guid fid)
        {
            
            var list = _scmCostplanService.GetEntityList(" cpm_id = '" + fid +"'"  );
            return list;
        }
        /// <summary>
        /// 根据Sql获取费用计划子表信息用于费用使用模块
        /// </summary>
        /// <returns></returns>
        public List<ScmCostplanInfo> GetCostplanBySql(string section,DateTime yearmonth)
        {

            var list = _scmCostplanService.GetEntityList(" cpm_id in (select cpm_id from scm_costplanmain where cpm_state=1 and  cpm_section  = '" + section + "' and cpm_yearmonth='" + yearmonth + "')");
            return list;
        }
         /// <summary>
        /// 根据Sql修改费用计划主表状态为已使用
        /// </summary>
        /// <returns></returns>
        public int UpdateCostPlanmainState(string section, DateTime yearmonth)
        {

            var rel = _scmCostplanmainService.UpdateCostPlanmainState(section, yearmonth);
            return rel;
        }
        
        /// <summary>
        /// 添加费用计划子表信息
        /// </summary>
        /// <returns></returns>
        public int AddCostplan(ScmCostplanInfo AddEntity)
        {
            return _scmCostplanService.InsertEntity(AddEntity);
        }
        /// <summary>
        /// 删除费用计划子表信息
        /// </summary>
        /// <param name="fid"></param>
        /// <returns></returns>
        public int DeleteCostplanByFId(string fid)
        {
            return _scmCostplanService.DeleteEntityByStringFID(fid);
        }
        /// <summary>
        /// 删除费用计划信息(批量删除)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int DeleteCostPlanmainMulti(string id)
        {
            var cp = _scmCostplanService.DeleteEntityByMultiStringID(id);
            return _scmCostplanmainService.DeleteEntityByMultiStringID(id);
        }
    }
}

